﻿using System;
using System.Globalization;
using System.Linq;
using System.Web.UI;
using Medianamik.Core;

namespace Medianamik.UI.Web.ModalWindows
{
    public partial class AddCultureWindow : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var currentCultures = ConfigManager.GetAllCultures();
                CultureName.DataSource = CultureInfo.GetCultures(CultureTypes.SpecificCultures).
                    Where(ci => !currentCultures.Any(c => c.CultureName == ci.Name)).
                    OrderBy(ci => ci.EnglishName);
                CultureName.DataTextField = "EnglishName";
                CultureName.DataValueField = "Name";
                CultureName.DataBind();
            }
        }

        protected void Add(object sender, EventArgs e)
        {
            var culture = new Culture(CultureName.SelectedValue, MedianamikActive.Checked,
                                      ContentManagementActive.Checked, 0);
            ConfigManager.SaveCulture(culture);
            ScriptManager.RegisterStartupScript(this, typeof (AddCultureWindow),
                                                "CloseWindow", "closeWindow();", true);
        }
    }
}